import Heap from "../09_堆结构Heap/06_堆结构Heap(二叉堆)";

class PriorityQueue<T> {
  private heap: Heap<T> = new Heap<T>();
  enqueue(value: T): void {
    this.heap.insert(value);
  }
  dequeue(): T | null {
    return this.heap.extract() || null;
  }
  peek(): T | null {
    return this.heap.peek() || null;
  }
  isEmpty(): boolean {
    return this.heap.isEmpty();
  }
  get size(): number {
    return this.heap.length;
  }
  print(): void {
    this.heap.print();
  }
}

class Student<T> {
  constructor(public value: T, public score: number) {}
  valueOf(): number {
    return this.score; // 堆排序的依据
  }
}

const queue = new PriorityQueue<Student<string>>();
queue.enqueue(new Student("李四", 80));
queue.enqueue(new Student("王五", 70));
queue.enqueue(new Student("张三", 90));

while (!queue.isEmpty()) {
  console.log(queue.dequeue());
}

export {};
